//package com.github.llyb120.service;
//
//import com.github.llyb120.compiler.java.BaseDynamicJavaCode;
//import com.github.llyb120.compiler.java.DynamicCode;
//import com.github.llyb120.compiler.java.DynamicJavaRunner;
//import com.github.llyb120.compiler.java.JavassistCompiler;
//import com.github.llyb120.logger.java.JavaLogger;
//import com.github.llyb120.logger.java.LoggerEntity;
//import com.github.llyb120.request.JavaSourceCodeRequest;
//import com.github.llyb120.response.JavaSourceCodeResponse;
//import org.apache.logging.log4j.util.Strings;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
///**
// * @Author: Administrator
// * @Date: 7/27/2021 11:47 AM
// */
//@Service
//public class JavaCodeRunService {
//
//    /**
//     * 运行javacode，需要对宏做一下处理
//     * @param request
//     * @return
//     */
//    public JavaSourceCodeResponse runCode(JavaSourceCodeRequest request){
//        String[] lines = request.getCode().split("\n");
//        for (int i = 0; i < lines.length; i++) {
//            lines[i] = lines[i].replaceAll("//#dump\\((.+?)\\)", String.format("logger._show(%d,$1);", i));
//        }
//        String src = String.join("\n", lines);
//        DynamicCode code = DynamicCode.builder()
//            .mainCode(src)
//            .build();
//        try{
////            BaseDynamicJavaCode runnable = JavassistCompiler.run(code);
//            BaseDynamicJavaCode runnable = DynamicJavaRunner.run(code);
//            JavaSourceCodeResponse resp = JavaSourceCodeResponse.builder()
//                .logs(runnable.getLogger().getLogs())
//                .loggerEntities(runnable.getLogger().getLoggerEntities())
//                .build();
//            return resp;
//        } catch (Exception e){
//            e.printStackTrace();
//            throw new RuntimeException("代码运行错误");
//        }
//    }
//}
